package com.hm.springcloud.jvm8.stream;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.UUID;

/**
 * @author shishun.wang
 * @date 下午3:35:32 2016年11月4日
 * @version 1.0
 * @describe
 */
public class HashMapTest {

	static Map<String, List<Integer>> map = new HashMap<String, List<Integer>>();

	static {
		for (int i = 0; i < 10; i++) {
			List<Integer> list = new ArrayList<Integer>();
			for (int j = 0; j < 1000; j++) {
				list.add(j);
			}
			map.put(UUID.randomUUID().toString(), list);
		}
	}

	public static void main(String[] args) {// 51311、51594

		map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).forEach(map -> {
			System.out.println(map);
		});

		System.out.println("1、---------------------------------");

		map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).map(Entry::getValue).forEach(value -> {
			System.out.println(value);
		});

		System.out.println("2、---------------------------------");

		map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).map(Entry::getValue).filter(Objects::nonNull)
				.forEach(avb -> {
					System.out.println(avb);
				});

		System.out.println("3、---------------------------------");

		map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).map(Entry::getValue).filter(Objects::nonNull)
				.flatMap(Collection::stream).forEach(aa -> {
					System.out.println(aa);
				});

		System.out.println("4、---------------------------------");

		long count = map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).map(Entry::getValue)
				.filter(Objects::nonNull).flatMap(Collection::stream).map(Integer::intValue).count();

		System.out.println(count);
	}
}
